function text_size(s) {
	$(".article-text").css("fontSize", s + "px").find("p").css("fontSize",
			s + "px");
}
function save_file() {
	document.execCommand("saveAs");
}
function install_article_tools() {
	var html = "";

	html = '<table width="100%" class="article-tools">';
	html += '<tr>';
	html += '	<td>';
	html += '<div style="LINE-HEIGHT: 12px" id="bdshare" class="bdshare_b">';
	html += '<img src="http://bdimg.share.baidu.com/static/images/type-button-1.jpg" />';
	html += '</div>';
	html += '</td>';
	html += '<td valign="middle" align="center"><img align="middle" src="images/icon_info.gif" />';
	html += '<a onclick="text_size(16)" href="javascript:void(0) ">大&nbsp;</a>';
	html += '<a onclick="text_size(14)" href="javascript:void(0)">中&nbsp;</a>';
	html += '<a onclick="text_size(12)" href="javascript:void(0)">小&nbsp;</a>';
	html += '</td>';
	html += '<td valign="middle" align="center"><img align="middle" ';
	html += 'src="images/icon_print.gif" /> <a href="javascript:void(0)" onclick="javascript:window.print();">打印</a>';
	html += '</td>';
	html += '<td valign="middle" align="center"><img align="middle" ';
	html += 'src="images/icon_save.gif" /> <a href="javascript:void(0)" ';
	html += 'onclick="save_file()">保存</a>';
	html += '</td>';
	html += '<td valign="middle" align="center"><img align="middle" ';
	html += 'src="images/icon_close.gif" /> <a href="javascript:void(0)"';
	html += 'onclick="javascript:window.close();">关闭</a>';
	html += '</td>';
	html += '</tr>';
	html += '</table>';

	document.write(html);
}
(function($) {
	$.extend({
		metadata : {
			defaults : {
				type : 'class',
				name : 'metadata',
				cre : /({.*})/,
				single : 'metadata'
			},
			setType : function(type, name) {
				this.defaults.type = type;
				this.defaults.name = name;
			},
			get : function(elem, opts) {
				var settings = $.extend({}, this.defaults, opts);
				// check for empty string in single property
				if (!settings.single.length)
					settings.single = 'metadata';

				var data = $.data(elem, settings.single);
				// returned cached data if it already exists
				if (data)
					return data;

				data = "{}";

				var getData = function(data) {
					if (typeof data != "string")
						return data;

					if (data.indexOf('{') < 0) {
						data = eval("(" + data + ")");
					}
				}

				var getObject = function(data) {
					if (typeof data != "string")
						return data;

					data = eval("(" + data + ")");
					return data;
				}

				if (settings.type == "html5") {
					var object = {};
					$(elem.attributes).each(function() {
						var name = this.nodeName;
						if (name.match(/^data-/))
							name = name.replace(/^data-/, '');
						else
							return true;
						object[name] = getObject(this.nodeValue);
					});
				} else {
					if (settings.type == "class") {
						var m = settings.cre.exec(elem.className);
						if (m)
							data = m[1];
					} else if (settings.type == "elem") {
						if (!elem.getElementsByTagName)
							return;
						var e = elem.getElementsByTagName(settings.name);
						if (e.length)
							data = $.trim(e[0].innerHTML);
					} else if (elem.getAttribute != undefined) {
						var attr = elem.getAttribute(settings.name);
						if (attr)
							data = attr;
					}
					object = getObject(data.indexOf("{") < 0 ? "{" + data + "}"
							: data);
				}

				$.data(elem, settings.single, object);
				return object;
			}
		}
	});

	$.fn.metadata = function(opts) {
		return $.metadata.get(this[0], opts);
	};

})(jQuery);

(function($) {

	$.fn.scrollPicture = function(options) {

		var opts = $.extend({}, $.fn.scrollPicture.defaults, options);

		var r = this
				.each(function() {
					var $this = $(this);
					var _this = this;

					_this.option = $.metadata ? $.extend({}, opts, $this
							.metadata()) : opts;
					this.init = function() {
						var id = $this.attr("id");
						var t = $("#" + id);
						var top = $("#" + id + "_top");
						var ul = $("#" + id + "_ul");

						var css = t.attr("class");
						var link = t.attr("link");
						top.addClass(css + "-top");
						var html_top = "<span class='" + css
								+ "-top-title'><a href='" + link + "'>"
								+ top.text() + "</a></span>";
						if (link != '') {
							html_top += "<span class='"
									+ css
									+ "-top-more'><a href='"
									+ link
									+ "' class='"
									+ css
									+ "-top-more-link'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</a></span>";
						}
						top.html(html_top);

						var html_temp = "";
						$("li>a", ul)
								.each(
										function(index) {
											var img = $(this).attr("img");
											var href = $(this).attr("href");
											html_temp += "<div class='"
													+ css
													+ "-content-images-item' href='"
													+ href
													+ "'><img  src='"
													+ img
													+ "' width='140' height='115' /><div>"
													+ $(this).text()
													+ "</div></div>";
										});
						var html_pics = "<div id='"
								+ id
								+ "_contain' style='width:900%;float:left;'><span class='"
								+ css + "-content-images-block' id='" + id
								+ "_tb1' >" + html_temp + "</span>";
						html_pics += "<span class='" + css
								+ "-content-images-block'  id='" + id
								+ "_tb2'>" + html_temp + "</span></div>";
						ul.remove();
						var btnleft = $(
								"<div class='" + css
										+ "-content-left-button'></div>")
								.click(function() {
									_this.scrollby(120);
								});
						var btnright = $(
								"<div class='" + css
										+ "-content-right-button'></div>")
								.click(function() {
									_this.scrollby(-120);
								});
						var panimages = $(
								"<div class='" + css
										+ "-content-images'></div>").append(
								$(html_pics));
						$("." + css + "-content-images-item", panimages).click(
								function(index) {
									window.location = $(this).attr("href");
								});
						$("<div class='" + css + "-content'></div>")
								.appendTo(t).append(btnleft).append(panimages)
								.append(btnright);

						this.tab1 = $("#" + id + "_tb1", panimages).get(0);
						this.tab2 = $("#" + id + "_tb2", panimages).get(0);
						this.tab = panimages.get(0);

						if (_this.option.enableMouse != undefined
								&& _this.option == true) {
							panimages.mouseover(function() {
								_this.stop();
							});
							panimages.mouseout(function() {
								_this.start(20);
							});
						}

						_this.timer = null;
					};
					this.scrollby = function(size) {
						_this.tab.scrollLeft += size;
						if (_this.tab2.offsetWidth - _this.tab.scrollLeft <= 0)
							_this.tab.scrollLeft -= _this.tab1.offsetWidth;

					};
					this.marque = function() {
						if (_this.tab2.offsetWidth - _this.tab.scrollLeft <= 0)
							_this.tab.scrollLeft -= _this.tab1.offsetWidth;
						else {
							_this.tab.scrollLeft++;
						}
					};
					this.start = function() {

						if (_this.timer == null) {

							_this.timer = setInterval(function() {
								_this.marque();
							}, _this.option.delay);
						}

					};

					this.stop = function() {
						if (_this.timer != null) {
							clearInterval(_this.timer);
							_this.timer = null;
						}
					};
					this.init();
				});
		return r;
	};
	$.fn.scrollPicture.defaults = {
		delay : 20,
		enableMouse : true
	};
})(jQuery);

// make column
(function($) {
	$.fn.makeColumn = function(options) {

		var opts = $.extend({}, $.fn.makeColumn.defaults, options);

		var r = this.each(function() {
			columnStyle($(this).attr("id"));
		});

		return r;
	};
	$.fn.makeColumn.defaults = {
		filter : "makecolumn"
	};
	function columnStyle(id) {

		/*
		 * <div id='col' class='css' link=''> <div id='col_top'>title</div>
		 * <ul> <li><a href=''>ABC</a><span>3425</span></li> </ul> </div>
		 */

		var t = $("#" + id);
		var top = $("#" + id + "_top");
		var ul = $("#" + id + "_ul");

		var css = t.attr("class");
		var link = t.attr("link");
		top.addClass(css + "-top");
		var html_top = "";
		if (link != '') {
			html_top += "<span class='"
					+ css
					+ "-top-more'><a href='"
					+ link
					+ "' class='"
					+ css
					+ "-top-more-link'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</a></span>";
		}
		html_top += "<span class='" + css + "-top-title'>" + top.text()
				+ "</span>";

		top.html(html_top);
		ul.remove();
		$("<div class='" + css + "-content'></div>").appendTo(t).append(ul);

	}
})(jQuery);

// make column stylish
(function($) {
	$.fn.makeStylish = function(options) {

		var opts = $.extend({}, $.fn.makeColumn.defaults, options);

		var r = this.each(function() {
			var _this = this;
			_this.option = $.metadata ? $.extend({}, opts, $(this).metadata())
					: opts;
			makeStylish(_this);
		});

		return r;
	};
	$.fn.makeStylish.defaults = {
		filter : "makecolumn",
		css : "column",
		secondcss : "",
		tplist : false
	};
	function makeStylish(ele) {

		/**
		 * 
		 * <div box> <div tabs> <div tab more id> <div id(title)>title</div>
		 * <ul>
		 * <li><a href='url' img></a><span>date</span></li>
		 * </ul>
		 * </div> <div tab more id> <div id(title)>title</div>
		 * <ul>
		 * <li><a href='url' img></a><span>date</span></li>
		 * </ul>
		 * </div> </div> </div>
		 */

		var css = ele.option.css;
		var root = $(ele).addClass(css).addClass(ele.option.secondcss);

		$("a[isnew='1']", root)
				.each(
						function(index) {
							$(this)
									.after(
											"<img style='float:left;margin-top:7px;'  border='0' src='images/new.gif'>");
						});

		var _width = root.innerWidth();
		var tabs = root.children(":first").addClass(css + "-content");
		var tablist = tabs.children();

		var top = $("<div></div>").addClass(css + "-top");

		var gtabs = null;

		if (tablist.length > 2) {
			gtabs = $("<div />").addClass(css + "-top-tabs");
			root.prepend(gtabs);
			gtabs = $("<ul></ul>").appendTo(gtabs);
			_width = _width / (tablist.length - 1) - 5;
		}
		root.prepend(top);

		tablist
				.each(function(index) {
					var _this = $(this);

					if (gtabs == null) { // only one tab
						if (index == 0) {

							var temp = _this.children(":first");

							var more = temp.attr("more");
							temp.remove();
							if (more != '') {
								var moreele = $("<span class='"
										+ css
										+ "-top-more'><a class='"
										+ css
										+ "-top-more-link' href='"
										+ more
										+ "'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</a></span>");
								moreele.appendTo(top);
							}
							var title = "<a href='" + more + "'>" + temp.text()
									+ "</a>";
							$("<span>" + title + "</span>").addClass(
									css + "-top-title").appendTo(top);
							_this.addClass(css + "-content-tab");
						}
					} else {// more tabs

						if (index == 0) {

							var temp = _this.children(":first");

							var more = temp.attr("more");
							temp.remove();

							if (more != '') {
								var moreele = $("<span class='"
										+ css
										+ "-top-more'><a class='"
										+ css
										+ "-top-more-link' href='"
										+ more
										+ "'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</a></span>");
								moreele.appendTo(top);
							}
							var title = "<a href='" + more + "'>" + temp.text()
									+ "</a>";
							$("<span>" + title + "</span>").addClass(
									css + "-top-title").appendTo(top);
							_this.remove();
						} else {
							var temp = _this.children(":first");
							var title = temp.text();
							var more = temp.attr("more");
							temp.remove();

							if (more != '') {
								title = "<a  href='" + more + "'>" + title
										+ "</a>";
							}
							var li = $("<li>" + title + "</li>")
									.addClass("unselected")
									.css("width", _width + "px")
									.appendTo(gtabs)
									.mouseover(
											function() {
												$(this)
														.parent()
														.children()
														.removeClass("selected");
												$(this).addClass("selected");
												tablist.hide();
												tablist.filter(
														":eq(" + (index) + ")")
														.show();
											});
							_this.addClass(css + "-content-tab");

							if (index == 1) {
								_this.show();
								li.addClass("selected");
							} else {
								_this.hide();
							}
						}

					}

				});

	}
})(jQuery);
